package c15;

/**
 * 模拟同时开始
 */
public class RacerWithMyLatch {
    static class Racer extends Thread {
        MyLatch latch;

        public Racer(MyLatch latch) {
            this.latch = latch;
        }

        @Override
        public void run(){
            this.latch.await();
            System.out.println(Thread.currentThread().getName()+" run...");
        }

    }

    public static void main(String[] args) {
        MyLatch myLatch = new MyLatch(1);
        for (int i = 0; i < 10; i++) {
            Racer racer = new Racer(myLatch);
            racer.start();
        }
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("main thread end");
        myLatch.countDown();
    }
}
